let Tools = (function (win, doc) {
  let toolFun = {
    // 数组扁平化函数 传入数组
    flatten: function (arr) {
      let toStr = {}.toString
      if (toStr.call(arr) !== '[object Array]') {
        throw new Error('只有数组可以使用')
      }

      return arr.reduce(function (prev, elem) {
        return prev.concat(
          toStr.call(elem) === '[object Array]'
                            ? this.flatten(elem)
                            : elem
        )
      }.bind(this), [])
    },
    // typeOf 数据类型检测
    myTypeof: function (val) {
      let type = typeof(val),
          toStr = Object.prototype.toString;
      let resSet = {
        '[object Object]': 'object',
        '[object Array]': 'array',
        '[object Number]': 'object-number',
        '[object String]': 'object-string',
        '[object boolean]': 'object-boolean',
        '[object Date]': 'date',
        '[object RegExp]': 'regexp',
        '[object Function]': 'function'
      }
      
      if (type === null) {
        return null
      } else if (type === 'object') {
        return resSet[toStr.call(val)]
      } else {
        return type
      }
    }
  }
  return toolFun
}(window, document))